package com.ruoyi.test.Interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class MyInterceptor implements HandlerInterceptor {
 
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        log.info("preHandle: " + request.getRequestURI());
        String contenType = request.getHeader("Content-Type");
        log.info("preHandle.Content-Type："+contenType);
        log.info("进入控制层前日志记录、监控");
        log.info("进入控制层前先进行登录验证");
        log.info("进入控制层前先进行用户对于的角色的权限验证");
        return true;
    }
 
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
        log.info("postHandle: " + request.getRequestURI());
        log.info("进入控制层时业务处理");
    }
 
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        log.info("afterCompletion: " + request.getRequestURI());
        log.info("完成控制层后日志记录、监控");
    }
}